package Sort;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        Integer [] a = {1, 65, 3, 12, 56, 12, 98, 55, 23, 32, 16, 11};
        System.out.println(Arrays.toString(a));
        bubbleSort(a);
        System.out.println(Arrays.toString(a));
    }

    public static void bubbleSort(Integer [] a){
        int length = a.length;
        Integer temp = 0;
        for (int i = 1; i < length; i++) {//第i次排序 只需要 length - 1 次
            for (int j = 0; j < length - i; j++) {
                if(a[j] > a[j+1] ){
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
    }
}
